package com.valeandre.euroro.utils;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import com.valeandre.euroro.R;

public class Utils {
	
	public static final Map<String, Integer> MATERIAL_IMAGE_RES_MAP = Collections.unmodifiableMap(new HashMap<String, Integer>() {
		private static final long serialVersionUID = 1L;

		{
			put("gold", R.drawable.gold_coin_single);
			put("silver", R.drawable.silver_coin_single);
			put("platinum", R.drawable.platinum_coin_single);
			put("palladium", R.drawable.palladium_coin_single);
			
		}

	});
	
	public static final Map<String, Integer> MATERIAL_NAME_RES_MAP = Collections.unmodifiableMap(new HashMap<String, Integer>() {
		private static final long serialVersionUID = 1L;

		{
			put("gold", R.string.gold);
			put("silver", R.string.silver);
			put("platinum", R.string.platinum);
			put("palladium", R.string.palladium);
			
		}

	});
	
	public static final Map<String, Integer> CURRENCYABBR_CURRENCY_MAP = Collections.unmodifiableMap(new HashMap<String, Integer>() {
		private static final long serialVersionUID = 1L;

		{
			put("AUD", R.string.AUD);
			put("BRL", R.string.BRL);
			put("CAD", R.string.CAD);
			put("CHF", R.string.CHF);
			put("CNY", R.string.CNY);
			put("EUR", R.string.EUR);
			put("GBP", R.string.GBP);
			put("INR", R.string.INR);
			put("JPY", R.string.JPY);
			put("MXN", R.string.MXN);
			put("RUB", R.string.RUB);
			put("USD", R.string.USD);
			put("ZAR", R.string.ZAR);
			
		}

	});
	
	public static String convertStreamToString(InputStream is) throws IOException {
		if (is != null) {
			Writer writer = new StringWriter();

			char[] buffer = new char[1024];
			try {
				Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
				int n;
				while ((n = reader.read(buffer)) != -1) {
					writer.write(buffer, 0, n);
				}
			} finally {
				is.close();
			}
			return writer.toString();
		} else {
			return "";
		}
	}

}
